package com.bracketbird.server.services;


import com.bracketbird.client.service.rtc.*;
import com.bracketbird.server.dao.*;
import com.bracketbird.server.repository.tournament.*;
import com.bracketbird.clientcore.appcontrol.*;

import java.util.*;

/**
 *
 */
public class RTCChangesActionHandler extends AbstractActionHandler implements ActionHandler<RTCChangesAction, RTCResult> {


    public RTCResult execute(RTCChangesAction  action) throws ApplicationException {

        TournamentRepository repos = new TournamentRepository();

        try {

            PMF.startTransaction();

            List<RTCEvent> events = repos.getTournamentLog(action.gettId(), action.getLatestServerLogId());
            RTCResponse r = new RTCResponse(RTCResponse.Status.succes, events);
            PMF.commitTransaction();

            return new RTCResult(r);
        }
        finally {
            PMF.endTransaction();
        }
    }

    public Class<RTCChangesAction > getActionType() {
        return RTCChangesAction .class;
    }


}